import { initializeApp } from 'firebase/app';
import { GoogleAuthProvider, getAuth, signInWithPopup } from 'firebase/auth';

import { getFirestore, doc, getDoc, setDoc } from 'firebase/firestore';
import { firebaseUser } from '../interface';

const firebaseConfig = {
  apiKey: 'AIzaSyC13ks5v28Rk8VwWE2Lw6HoRsZgYIBRIEA',
  authDomain: 'crwn-clothing-db-15f7f.firebaseapp.com',
  projectId: 'crwn-clothing-db-15f7f',
  storageBucket: 'crwn-clothing-db-15f7f.appspot.com',
  messagingSenderId: '256576523668',
  appId: '1:256576523668:web:eb143a7e86074a0fcd5381',
};

// Initialize Firebase
const firebaseApp = initializeApp(firebaseConfig);

const provider = new GoogleAuthProvider();
provider.setCustomParameters({
  prompt: 'select_account',
});

export const auth = getAuth();
export const signInWithGooglePopup = () => signInWithPopup(auth, provider);

export const db = getFirestore();

export const createUserDocumentFromAuth = async (userAuth: firebaseUser) => {
  const userDocRef = doc(db, 'users', userAuth.uid)
  console.log(userDocRef);
}
